<?php
	require_once("../../../include/connect.php");
	require_once("../../../include/datetime.php");
	
	$category = $_POST['select'];
	$topic = $_POST['tieude'];
	$content_sum = $_POST['tomtat'];
	$content = $_POST['noidung'];
	$d = day_now();
	
	if( (($_FILES["file"]["type"] == "image/gif") || 
		 ($_FILES["file"]["type"] == "image/jpeg") ||
		 ($_FILES["file"]["type"] == "image/jpg") || 
		 ($_FILES["file"]["type"] == "image/pjpeg") || 
		 ($_FILES["file"]["type"] == "image/x-png") || 
		 ($_FILES["file"]["type"] == "image/png") ) && ($_FILES["file"]["size"] < 200000) )
	{
		if ($_FILES["file"]["error"] > 0)
    		header("Location:../index.php?p=new&msg=err&info=".$_FILES["file"]["error"]."");
		else
			if (file_exists("../../../img/upload/".$_FILES["file"]["name"]))
		      header("Location:../index.php?p=new&msg=exist&info=".$_FILES["file"]["name"]."");
    		else
				if($category != "" && $topic != "" && $content_sum != "" && $content != "")
				{
					move_uploaded_file($_FILES["file"]["tmp_name"], "../../../img/upload/".$_FILES["file"]["name"]);
					
					$query = mysql_query(" INSERT INTO news(category_id,topic,avatar,content_sum,content,date)
								VALUES('$category', N'$topic', '".$_FILES["file"]["name"]."', N'$content_sum', N'$content', '$d') ");
					if($query)
						header("Location:../index.php?p=new&msg=success");	
				}
      			else
					header("Location:../index.php?p=new&msg=null");
					//echo $category."-".$topic."-".$content_sum."-".$content;
	}
	else
		header("Location:../index.php?p=new&msg=err_type");	
		
?>
